package BFS_DFS;

import java.util.Scanner;

//是否能走出去
public class DFS迷宫问题1 {
    static int n;//行
    static int m;//列
    static int[][] maze;//迷宫
    static boolean[][] vis;//访问标记
    static int[][] dir=new int[][]{
            {-1,0},{1,0},{0,-1},{0,1}//上下左右
    };

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        maze=new int[n][m];
        vis=new boolean[n][m];
        int startX=-1,startY=-1;//存储起点位置
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maze[i][j]=sc.nextInt();
                if(maze[i][j] == 0 && startX == -1 && startY == -1){//找到起点
                    startX = i;
                    startY = j;
                }
            }
        }
        sc.close();
        if(startX == -1 || startY == -1){//没有可走的起点
            System.out.println("no");
            return;
        }
        String ans=dfs(startX, startY)?"yes":"no";
        System.out.println(ans);
    }

    static boolean dfs(int x,int y){
        if(maze[x][y]==2){
            return true;
        }
        vis[x][y]=true;
        for (int i = 0; i < 4; i++) {
            int tx=x+dir[i][0];
            int ty=y+dir[i][1];
            if(inMaze(tx,ty)&&!vis[tx][ty]&&(maze[tx][ty] == 0 || maze[tx][ty] == 2)){
                //能走的路径是0或2
                if(dfs(tx,ty)){
                    return true;
                }
            }
        }
        return false;
    }

    static boolean inMaze(int x,int y){//确保在迷宫范围内
        return (0<=x&&x<n&&0<=y&&y<m);
    }
}



